﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_ScheduleDetailController : BaseApiController
    {
        #region DI

        public PB_ScheduleDetailController(IPB_ScheduleDetailBusiness pB_ScheduleDetailBus)
        {
            _pB_ScheduleDetailBus = pB_ScheduleDetailBus;
        }

        IPB_ScheduleDetailBusiness _pB_ScheduleDetailBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_ScheduleDetail>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_ScheduleDetailBus.GetDataListAsync(input);
        }
        [HttpPost]
        public async Task<PageResult<PB_ScheduleDetailDTO>> GetDataListAsyncDtoList(PageInput<PB_ScheduleDetailConditionDTO> input)
        {
            return await _pB_ScheduleDetailBus.GetDataListAsyncDtoList(input);
        }
        /// <summary>
        ///  查找 生产排班dto
        /// </summary>
        [HttpPost]
        public async Task<List<PB_ScheduleDetailDTO>> GetDataListByArea()
        {
            var res = await _pB_ScheduleDetailBus.GetDataList();
            return res;
        }
        /// <summary>
        ///  查找 生产排班dto
        /// </summary>
        [HttpPost]
        public async Task<List<PB_ScheduleDetailUserDTO>> GetDataListByAreaid(string ID)
        {
            var res = await _pB_ScheduleDetailBus.GetDataListid(ID);
            return res;
        }

        [HttpPost]
        public async Task<PageResult<PB_ScheduleDetailUserDTO>> GetDataListByAreaidinfo(PageInput<ConditionDTO> input, string ID)
        {
            return await _pB_ScheduleDetailBus.GetDataListByAreaids(input, ID);
        }

        [HttpPost]
        public async Task<List<PB_ScheduleDetailUserDTO>> GetDataListByAreaids(string ids)
        {
            var res = await _pB_ScheduleDetailBus.GetDataListids(ids);
            return res;
        }

        //public async Task<List<PB_ScheduleDetailUserDTO>>
        /// <summary>
        ///  根据排班日期 进行查找用户信息
        /// </summary>
        [HttpPost]
        public async Task<List<PB_ScheduleDetailDTO>> GetDataListByTime(DateTime? CreateTime, DateTime? oldTime)
        {
            var res = await _pB_ScheduleDetailBus.GetDataTimeList(CreateTime,oldTime);
            return res;
        }
        /// <summary>
        ///  根据组织编号 查询人员信息
        /// </summary>
        [HttpPost]
        public async Task<List<PB_ScheduleDetailDTO>> GetDataDeptList(String Deptid)
        {
            var res = await _pB_ScheduleDetailBus.GetDataDeptList(Deptid);
            return res;
        }
        [HttpPost]
        public async Task<PB_ScheduleDetail> GetTheData(IdInputDTO input)
        {
            return await _pB_ScheduleDetailBus.GetTheDataAsync(input.id);
        }
        /// <summary>
        /// 联合查询生产排班 listdto 查找当前生产排班的子排班明细
        /// </summary>
        /// <param name="input">条件信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<PB_ScheduleDetailListDTO>> GetDataListShowAllName(PB_ProductionOrderDetailInput input)
        {
            return await _pB_ScheduleDetailBus.GetDataListShowAllNameAsync(input);
        }
        /// <summary>
        ///  查找所有 白班的用户
        /// </summary>
        [HttpPost]
        public async Task<List<PB_ScheduleDetailDTO>> GetDataByDayshift()
        {
            var res = await _pB_ScheduleDetailBus.GetDataByDayshift();
            return res;
        }
        /// <summary>
        /// 查询所有上夜班的用户
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<PB_ScheduleDetailDTO>> GetDataByNightshift()
        {
            var res = await _pB_ScheduleDetailBus.GetDataByNightshift();
            return res;
        }
        /// <summary>
        /// 大屏显示当日派工人数                    出勤报工人数(夜班、晚班和全班推迟一天统计)
        /// </summary>
        /// <param name="Days">前第几天</param>
        /// <returns>当日派工人次           出勤报工人数</returns>
        [HttpPost]
        [NoCheckJWT]
        public ScreenDisplayValue3DTO GetTodayScheduleAttendNums(int Days=0)
        {
            return _pB_ScheduleDetailBus.GetTodayScheduleAttendNums(Days);
        }
        /// <summary>
        /// 大屏显示七日派工人数                 出勤人数(夜班、晚班和全班推迟一天统计)
        /// </summary>
        /// <param name="Days">前第几天</param>
        /// <returns>七日派工人次          出勤人数</returns>
        [HttpPost]
        [NoCheckJWT]
        public ScreenDisplayBarChartDTO Get7DaysScheduleAttendNums(int Days=0)
        {
            return _pB_ScheduleDetailBus.Get7DaysScheduleAttendNums(Days);
        }
        /// <summary>
        /// 大屏显示当日排班派工率           出勤率(夜班、晚班和全班推迟一天统计)
        /// </summary>
        /// <param name="Days">前第几天</param>
        /// <returns>当日排班派工率          出勤率</returns>
        [HttpPost]
        [NoCheckJWT]
        public ScreenDisplayDashboardDTO GetScheduleAttendRate(int Days=0)
        {
            return _pB_ScheduleDetailBus.GetScheduleAttendRate(Days);
        }
        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_ScheduleDetail data, string USERIDS)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_ScheduleDetailBus.AddDataAsync(data);
            }
            else
            {
                await _pB_ScheduleDetailBus.UpdateDataAsync(data, USERIDS);
            }
        }

        [HttpPost]
        public async Task BatchtonightShiftType(PB_ScheduleDetail data) {
        
                await _pB_ScheduleDetailBus.BatchtonightShift(data);
           
        }
       /// <summary>
       /// 删除
       /// </summary>
       /// <param name="ids"></param>
       /// <returns></returns>
        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_ScheduleDetailBus.DeleteDataAsync(ids);
        }

        /// <summary>
        /// 批量修改 白班
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]   //list<string> buid
        public async Task TestSqlData(string id)
        {
          
            await _pB_ScheduleDetailBus.TestSqlDataAsync(id);
        }

        /// <summary>
        /// 批量修改夜班
        /// </summary>
        /// <param name="id">通过id 修改夜班  </param>
        /// <returns></returns>
        [HttpPost]
        public async Task BatchNightShift(string id) {
            await _pB_ScheduleDetailBus.BatchNightShift(id);
        }
        #endregion
    }
}